<?php
function SetTwitterBG($Profile)
{
	$tProfileUrl = 'https://twitter.com/' . $Profile;
	$curl_var = curl_init();
	curl_setopt($curl_var,CURLOPT_URL,$tProfileUrl);
	curl_setopt($curl_var, CURLOPT_HEADER, 1);
	curl_setopt($curl_var, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl_var, CURLOPT_HEADER, false); 
	$data = curl_exec($curl_var);
	curl_close($curl_var);
	
	$pat = '/body\\s*?{\\n\\s*background:\\s*?(#\\w*)\\s*?url\\(\'(.*)\'\\)\\s?(.*);/';
	//body\s*?{\n\s*background:\s*?(#\w*)\s*?url\(\'(.*)\'\)\s?(.*);
	$matchRet = preg_match_all($pat, $data, $m);
	if($matchRet)
	{
		$bgimg = preg_replace('/https?:\/\/\w+([0-9])\.twimg\.com/i','https://s3.amazonaws.com/twitter_production',implode("", $m[2]));
		echo '<style type="text/css">';
		echo 'body{ background: '.implode("", $m[1])." url('" . $bgimg . "') " . " " . implode("", $m[3]);
		echo '; }';
		echo '</style>';

	}
	else
	{
		echo '<style type="text/css">';
		echo "body{ background: #C0DEED url('img/bg-clouds.png') fixed repeat-x;}";
		echo '</style>';
	}
}
?>
